(function(jQuery) {
	/*
	 * 客户账号查询放大镜JS插件
	 */

	var gridColMenu_Detail = null;

	$.MagnifierPSQYUtils = {
		/**
		 * 页面初始化函数
		 */
		init : function() {
			var deliverRegion = encodeURI($("#deliverRegion").val());
			var deliverRegionType = encodeURI($("#deliverRegionType").val());
			var deliverRegionStatus = encodeURI($("#deliverRegionStatus").val());
			
			// 创建列表DataGrid
			$('#magnifierPSQYPage_psqy')
					.datagrid(
							{
								url : 'magnifier/getMagnifierPSQYList.json?catch=' + new Date() 
									+ '&deliverRegion=' + deliverRegion
									+'&deliverRegionType='+deliverRegionType
									+'&deliverRegionStatus='+deliverRegionStatus
									+'&Login_SessionId='+sessionId,
								method : 'get',
								iconCls : 'icon-large-smartart',
								pagination : true,
								rownumbers : true,
								striped : true,
								pageSize : 20,
								pageList : [20,40,100,200,500],
								columns : [[{
									field : 'id',
									title : "",
									hidden : true,
									width : 0,
									align : 'left'
								}, {
									field : 'deliverRegion',
									title : "配送区域",
									width : 211,
									align : 'left'
								}, {
									field : 'chineseName',
									title : "中文名称",
									width : 200,
									align : 'left'
								}, {
									field : 'englishName',
									title : "英文名称",
									width : 200,
									align : 'left'
								}, {
									field : 'deliverRegionType',
									title : "类型",
									width : 80,
									align : 'left'
								}, 
								{
									field : 'deliveryAreaType',
									title : "配送区域类型",
									width : 80,
									align : 'left'
								},{
									field : 'deliverRegionStatus',
									title : "激活",
									width : 60,
									align : 'left'
								}]],

								onDblClickRow : function(rowIndex, rowData) {
									//向父页面赋值
									if ($('#magnifierPSQYPage_id').val() != null && $('#magnifierPSQYPage_id').val().length > 0) {
										$("#" + $('#magnifierPSQYPage_id').val()).val(rowData.id);
									}
									if ($('#magnifierPSQYPage_code').val() != null && $('#magnifierPSQYPage_code').val().length > 0) {
										$("#" + $('#magnifierPSQYPage_code').val(),
												window.parent.document).searchbox(
												'setValue', rowData.deliverRegionStatusCode);
									}
									if ($('#magnifierPSQYPage_chinese_name').val() != null && $('#magnifierPSQYPage_chinese_name').val().length > 0) {
										$("#" + $('#magnifierPSQYPage_chinese_name').val(),
												window.parent.document).textbox('setValue', rowData.chineseName);
									}
									if ($('#magnifierPSQYPage_english_name').val() != null && $('#magnifierPSQYPage_english_name').val().length > 0) {
										$("#" + $('#magnifierPSQYPage_english_name').val(),
												window.parent.document).textbox('setValue', rowData.englishName);
									}
									if ($('#magnifierPSQYPage_type').val() != null && $('#magnifierPSQYPage_type').val().length > 0) {
										$("#" + $('#magnifierPSQYPage_type').val(),
												window.parent.document).val(rowData.deliverRegionType);
									}
									if ($('#magnifierPSQYPage_status').val() != null && $('#magnifierPSQYPage_status').val().length > 0) {
										$("#" + $('#magnifierPSQYPage_status').val(),
												window.parent.document).val(rowData.deliverRegionStatus);
									}
									
									//关闭放大镜窗口
									$("#magnifier_window").window('close');
								},
								onLoadError: function(){
									$.LmisUtils.opLoadError();
								}
							});
		},

		/**
		 * 查询
		 */
		search : function() {
		var deliverRegion = encodeURI($("#deliverRegion").textbox("getValue"));
		var deliverRegionType = encodeURI($("#deliverRegionType").combobox("getValue"));
		var deliverRegionStatus = encodeURI($("#deliverRegionStatus").combobox("getValue"));
			$('#magnifierPSQYPage_psqy')
					.datagrid(
							{
								url : 'magnifier/getMagnifierPSQYList.json?catch=' + new Date() 
								+ '&deliverRegion=' + deliverRegion
								+'&deliverRegionType='+deliverRegionType
								+'&deliverRegionStatus='+deliverRegionStatus
								+'&Login_SessionId='+sessionId
							});
		},
		undo : function(){
			$("#deliverRegion").textbox("setValue","");
			$("#deliverRegionStatus").combobox("setValue","");
		}
	};
})(jQuery);
$.MagnifierPSQYUtils.init();
